﻿using Fonour.Application.Services.Interfaces;
using Fonour.Utility;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Fonour.MVC.Components
{
    [ViewComponent(Name = "Navigation")]
    public class NavigationViewComponent : ViewComponent
    {
        private readonly IMenuAppService _menuAppService;
        private readonly IUserAppService _userAppService;
        public NavigationViewComponent(IMenuAppService menuAppService, IUserAppService userAppService)
        {
            _menuAppService = menuAppService;
            _userAppService = userAppService;
        }

        public async Task<IViewComponentResult> InvokeAsync()
        {
            Guid userId = Guid.Empty;
            byte[] bUserId;
            if (HttpContext.Session.TryGetValue("CurrentUserId", out bUserId))
            {
                userId = ByteConvertHelper.Bytes2Object<Guid>(bUserId);
            }

            var menus = await _menuAppService.GetMenusByUserAsync(userId);
            return View(menus);
        }
    }
}
